/*
 * AboutDialog.java
 * 
 * last update: 14.01.2010 by Stefan Saru
 * 
 * author:	Felix(felix@ulise.cs.pub.ro)
 * 
 * Obs: N/A
 */
package ide;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.io.FileReader;
import java.io.Reader;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;

@SuppressWarnings("serial")
public class AboutDialog extends JDialog {

	public AboutDialog(JFrame f) {
		super(f, "About vIDE ", true);

		setResizable(false); 

		JTabbedPane tabs = new JTabbedPane(SwingConstants.TOP);


		JLabel imageLabel = new JLabel((Icon) new ImageIcon(vide.baseDir + "images/splash.gif"));

		tabs.addTab( "About vIDE", null, imageLabel);


		JPanel infoPanel = new JPanel(new GridLayout(11, 1, 0, 0));
		java.util.Properties  properties;

		Runtime rt = Runtime.getRuntime();
		long freeMem, totalMem;


		freeMem = rt.freeMemory() >> 10;
		totalMem = rt.totalMemory() >> 10;

		try {
			properties = System.getProperties();
			infoPanel.add(new JLabel("Operating system :" + properties.getProperty("os.name")));
			infoPanel.add(new JLabel("OS version :" + properties.getProperty("os.version")));
			infoPanel.add(new JLabel("os.architecture : " + properties.getProperty("os.arch")));
			infoPanel.add(new JLabel("java.vm.name :" + properties.getProperty("java.vm.name")));
			infoPanel.add(new JLabel("java.vm.info :" + properties.getProperty("java.vm.info")));
			infoPanel.add(new JLabel("java.vm.version :" + properties.getProperty("java.vm.version")));
			infoPanel.add(new JLabel("java.version :" + properties.getProperty("java.version")));
			infoPanel.add(new JLabel("JIT compiler :" + properties.getProperty("java.compiler")));
			infoPanel.add(new JLabel("Java Class Version :" + properties.getProperty("java.class.version")));
			infoPanel.add(new JLabel("Total virtual machine memory :" + totalMem));
			infoPanel.add(new JLabel("Free virtual machine memory :" + freeMem));
		} catch(SecurityException ex) {
			infoPanel.add(new JLabel("Security Excpetion: Cannot access System.getProperties()"));
		} 

		tabs.addTab( "Sys Info", null, infoPanel);

		JPanel aboutUsPanel = new JPanel(new GridLayout(15, 1, 0, 0));
		aboutUsPanel.add(new JLabel("vIDE - The Definitive Interplatform Verilog IDE(c) 1999 pChr"));
		aboutUsPanel.add(new JLabel("Copyright (c) 1999 - 0001"));
		aboutUsPanel.add(new JLabel(""));
		aboutUsPanel.add(new JLabel("Team:"));

		aboutUsPanel.add(new JLabel("Chief programmer: Alexandru Panoviciu"));
		aboutUsPanel.add(new JLabel(""));
		aboutUsPanel.add(new JLabel("Raluca Ionescu (ide)"));
		aboutUsPanel.add(new JLabel("Daniel Pavel (engine) [power@sundy.cs.pub.ro]"));
		aboutUsPanel.add(new JLabel("Alexandru Panoviciu (engine, middle) [alecu@sundy.cs.pub.ro]"));
		aboutUsPanel.add(new JLabel("Lucian Felix Ghita (ide, middle, artwork) [felix@ulise.cs.pub.ro]"));
		aboutUsPanel.add(new JLabel(""));   
		aboutUsPanel.add(new JLabel("Made at the"));
		aboutUsPanel.add(new JLabel("Computer Science Departament of the"));
		aboutUsPanel.add(new JLabel("\"Politehnica\" University of Buchrest, Romania"));

		tabs.addTab( "Credits", aboutUsPanel);

		JPanel licensePanel = new JPanel();
		JTextArea licenseTextArea = new JTextArea();
		try {
			licenseTextArea.read((Reader) (new FileReader(vide.baseDir + "Documentation/license")), null);
		} catch (Exception e) {
			System.out.println("Cannot find license file.");
			licenseTextArea.setText("IOException: license file not foud in ./Documentation");
		}
		licenseTextArea.setEditable(false); 
		//licenseTextArea.setMaximumSize(new Dimension(190, 200));

		JScrollPane scroller = new JScrollPane(licenseTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS  );
		//scroller.setMaximumSize(new Dimension(100, 200));
		//licensePanel.add(scroller);

		scroller.setMaximumSize(new Dimension(100, 200));
		scroller.setSize(new Dimension(100, 200));
		scroller.setPreferredSize(new Dimension(100, 200));
		tabs.addTab("License", scroller);
		//those sizes give me headakes


		//licensePanel.setMaximumSize(new Dimension(150, 200));

		//scroller.setSize(new Dimension(100, 200));
		//licensePanel.setSize(new Dimension(150, 200));

		getContentPane().setLayout( new BorderLayout() );
		getContentPane().add(tabs, BorderLayout.CENTER);

		JButton ok = new JButton("OK");
		ok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				OKPressed();
			}});
		JPanel p = new JPanel();
		p.setLayout( new BorderLayout() );
		p.add(ok, BorderLayout.EAST );
		getContentPane().add(p, BorderLayout.SOUTH );

		getRootPane().setDefaultButton(ok);
		pack();

		scroller.setMaximumSize(new Dimension(100, 200));
		scroller.setSize(new Dimension(100, 200));
		scroller.setPreferredSize(new Dimension(100, 200));

		centerDialog();
	}

	protected void centerDialog() {
		Dimension screenSize = this.getToolkit().getScreenSize();
		Dimension size = this.getSize();
		screenSize.height = screenSize.height/2;
		screenSize.width = screenSize.width/2;
		size.height = size.height/2;
		size.width = size.width/2;
		int y = screenSize.height - size.height;
		int x = screenSize.width - size.width;
		this.setLocation(x,y);
	}

	public void OKPressed() {
		this.setVisible(false);
	}
}

